package com.zwj.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zwj.entity.Conversation;
import com.zwj.service.ConversationService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/conversation")
@CrossOrigin
public class ConversationController {

    @Resource
    private ConversationService conversationService;


    @GetMapping("/getConversations/{username}")
    public List<Conversation> getConversations(@PathVariable("username") String username){

        LambdaQueryWrapper<Conversation> conversationWrapper =
                new LambdaQueryWrapper<>();

        conversationWrapper.eq(Conversation::getUsername1,username)
                .or().eq(Conversation::getUsername2,username);

        return conversationService.list(conversationWrapper);

    }
}
